module.exports = function($scope, $state, $stateParams,$resource,$modal,toaster){  
    console.log('1111');
    console.log($stateParams.type);
    $scope.type = $stateParams.type;
  /* 分页
        * ========================================= */
    $scope.maxSize = 5;             //最多显示多少个按钮
    $scope.bigCurrentPage = 1;      //当前页码
    $scope.itemsPerPage = 10         //每页显示几条
    $scope.searchform = {};
    $scope.getlist = function () {
        var para = {
            pageNo:$scope.bigCurrentPage, 
            pageSize:$scope.itemsPerPage
        };
        para = angular.extend($scope.searchform, para);
        $resource('/api/ac/cdc/leagueCardCheckProductService/findCardCheckList', {}, {}).
        save(para,function(res) {
            if (res.errcode !== 0) {
                toaster.error({title:"",body:res.errmsg});
                return;
            }
            console.log(res);
            $scope.objs = res.data.results;
            $scope.bigTotalItems = res.data.totalRecord;
        })
    };
     
    $scope.getlist();

    $scope.create = function() {
        $scope.item = {};
        $scope.flag = 'create';
        var modalInstance = $modal.open({
          template: require('../views/leagueAddProduct.html'),
          controller: 'leagueAddProduct',
          size: 'lg',
          resolve: {
            item: function () {
                return $scope.item;
            },
            type: function () {
                return $scope.type;
            },
            flag: function () {
                return $scope.flag;
            },
          }
        });
        modalInstance.result.then(function (showResult) {	
            $scope.getlist();
        });
    };
    $scope.detail = function(item) {
        $scope.flag = 'detail';
        var modalInstance = $modal.open({
        template: require('../views/leagueAddProduct.html'),
        controller: 'leagueAddProduct',
        size: 'lg',
        resolve: {
            item: function () {
                return item;
            },
            type: function () {
                return $scope.type;
            },
            flag: function () {
                return $scope.flag;
            },
        }
        });
        modalInstance.result.then(function (showResult) {	
            $scope.getlist();
        });
        // $state.go('app.addnewsrolling',{'id':id});
    };
    // 删除
    $scope.delete = function(id) {
        if (confirm('确定要删除吗?')) {
            $resource('api/ac/cdc/leagueCardCheckProductService/updatedel', {}, {}).            
            save({'place_id': place_id},function(res) {
                if (res.errcode !== 0) {
                    toaster.error({title:"",body:res.errmsg});
                    return;
                } 
                toaster.success({title:"",body:"删除成功"});                
                $scope.getlist();
            })
            return;
        } 
        
    };
    // 发布
    $scope.public = function(place_id){
      if (confirm('确定要发布吗?')) {
        $resource('/api/ac/cdc/leagueCardCheckProductService/updateCardCheckStateOn', {}, {}).
        save({'place_id': place_id},function(res) {
            if (res.errcode !== 0) {
                toaster.error({title:"",body:res.errmsg});
                return;
            }
            console.log(res);
            toaster.success({title:"",body:"发布成功"});
            $scope.getlist();
        })
        return;
      } 
    }
  // 撤回
  $scope.withdraw = function(place_id){
    if (confirm('确定要撤回吗?')) {
      $resource('/api/ac/cdc/leagueCardCheckProductService/updateCardCheckStateOff', {}, {}).
      save({'place_id': place_id},function(res) {
          if (res.errcode !== 0) {
              toaster.error({title:"",body:res.errmsg});
              return;
          }
          console.log(res);
          toaster.success({title:"",body:"撤回成功"});
          $scope.getlist();
      })
      return;
    } 
  }

    $scope.edit = function(item) {
        $scope.flag = 'edit';
        var modalInstance = $modal.open({
        template: require('../views/leagueAddProduct.html'),
        controller: 'leagueAddProduct',
        size: 'lg',
        resolve: {
            item: function () {
                return item;
            },
            type: function () {
                return $scope.type;
            },
            flag: function () {
                return $scope.flag;
            },
         }
        });
        modalInstance.result.then(function (showResult) {	
            $scope.getlist();
        });
        // $state.go('app.addnewsrolling',{'id':id});
     };


    
    

 

};